package sk.demo.jpa.repository;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import sk.demo.jpa.entity.Message;

import java.util.List;

/**
 * @author sk.z
 */
public interface MessageRepository extends JpaRepository<Message, Long> {

    List<Message> findByUserId(String userId);

    @Query("select new sk.demo.jpa.entity.Message(mesId,content) from message where userId=?1 and mesId > ?2 ")
    List<Message> getByUserGtId(String user, Long id);

    @Query("select m from message m where content like %:segment% ")
    List<Message> getByContent(@Param("segment") String segment, Pageable page);

}
